package sort;

import java.util.Arrays;
import java.util.Scanner;

public class BubbleSort
{
    public static void main (String[] args)
    {
        Scanner scan = new Scanner(System.in);
        System.out.println("begin");
        System.out.println("请随意输入10个数字：");
        
        int[] bubble = new int[10];
        
        for(int i = 0; i < bubble.length; i++)
        {
            bubble[i] = scan.nextInt();
        }
        
        System.out.println("原数组：" + Arrays.toString(bubble));
        bubblesort(bubble);
        System.out.println("排序完毕。");
    }
    
    public static void bubblesort(int[] a)
    {
        int middle = 0;
        
        for(int j = 0; j < a.length; j++)
        {
            boolean bool = true;
            
            for(int k = 0; k < a.length - 1 - j; k++)
            {
                if(a[k] > a[k + 1])
                {
                    middle = a[k];
                    a[k] = a[k + 1];
                    a[k + 1] = middle;
                    bool = false;
                }
            }
            
            System.out.println("第" + (j + 1) + "次排序：" + Arrays.toString(a));
            
            if(bool)
            {
                break;
            }
        }
    }
}
